class Plan < ApplicationRecord
  enum propose: [:win, :lose, :big, :small, :one, :two]

  enum state: [:pending, :completed]
  
  belongs_to :user
  belongs_to :team

  has_many :bets

  def win_money
    fee = 0.0
    self.bets.where(state: :win).each do |bet|
      fee += bet.total_fee
    end
    self.bets.where(state: :winned_half).each do |bet|
      fee += bet.total_fee
    end
    fee
  end
  
  def lose_money
    fee = 0.0
    self.bets.where(state: :lose).each do |bet|
      fee += bet.total_fee
    end
    self.bets.where(state: :losed_half).each do |bet|
      fee += bet.total_fee
    end
    fee
  end
  
end
